/****
 * @function dimension 
 * @dedescription 一维数组转二维数组  
 * @param {Object} options 对象参数
 * @prop  {Array} [options.oldArr] 数组
 * @prop  {Number} [options.num = 4] 每个数组个数默认4
 * 
 *****/
const dimension = ({
	oldArr,
	num = 4
}) => {
	let list = []
	for (let i = 0; i < oldArr.length; i += num) {
		list.push(oldArr.slice(i, i + num));
	}
	return list
}


/***
 *  @function HMS_daxiao 
 * 	@dedescription 时间比较大小
 * @param {Object} options 对象参数
 * @prop {String} options.time 时间1
 * @prop {String} options.time  时间2
 *  @prop {Boolean} options.format 是否需要补0
 **/

const HMS_daxiao = ({
	str1,
	str2,
	format
}) => {
	let arr1 = str1.split(':');
	let arr2 = str2.split(':');
	if (format) {
		arr1[0] < 10 ? arr1[0] = '0' + arr1[0] : ''; //将小时转化为两位数
		arr1[1] < 10 ? arr1[1] = '0' + arr1[1] : ''; //将分钟转化为两位数
		arr1[2] < 10 ? arr1[2] = '0' + arr1[2] : ''; //将秒转化为两位数
		arr2[0] < 10 ? arr2[0] = '0' + arr2[0] : '';
		arr2[1] < 10 ? arr2[1] = '0' + arr2[1] : '';
		arr2[2] < 10 ? arr2[2] = '0' + arr2[2] : '';
	}
	str1 = Number(arr1.join(''));
	str2 = Number(arr2.join(''));

	return str1 - str2
	// 小于0则str1时间小，大于0则str1时间大

};
/***
 *  @functione getDatetime 
 * @dedescription 获取当前时间
 * @param {String} sep 时间分隔符号默认值"-"
 **/
const getDatetime = (sep = "-") => {
	//获取当前的年月日
	let date_ = new Date();
	let year = date_.getFullYear();
	let month = date_.getMonth() + 1;
	let strDate = date_.getDate();
	return year + sep + month + sep + strDate
}

/***
 *  @functione GetDateStr 
 * @dedescription n天后
 * @param {Number} AddDayCount 天数
 **/
const GetDateStr = (AddDayCount) => {
	let dd = new Date();
	dd.setDate(dd.getDate() + AddDayCount);
	let y = dd.getFullYear();
	let m = (dd.getMonth() + 1) < 10 ? "0" + (dd.getMonth() + 1) : (dd.getMonth() + 1); //获取当前月份的日期，不足10补0
	let d = dd.getDate() < 10 ? "0" + dd.getDate() : dd.getDate(); //获取当前几号，不足10补0
	return y + "-" + m + "-" + d;
}

/***
 *  @functione getWeek 
 * @dedescription 获取date是周几
 * @param {String} date日期时间
 **/
const getWeek = (date) => {
	let week = 0;
	if (date) {
		week = new Date(date).getDay();
	} else {
		week = new Date().getDay();
	}
	const weekList = ['日', '一', '二', '三', '四', '五', '六'];
	return weekList[week]
}

/***
 *  @functione underDevelopment 
 * @dedescription 功能开发中
 **/
const underDevelopment = () => {
	uni.showToast({
		icon: "none",
		title: "功能开发中，敬请期待"
	})
}
/***
 *  @functione timeStrGetDate 
 * @dedescription 时间戳获取日期
 **/
const timeStrGetDate = (timeStr) => {
	let str = 1000 * timeStr;
	if (isNaN(str)) {
		str = timeStr
	}
	const date = new Date(str);
	const year = date.getFullYear();
	const month = ('0' + (date.getMonth() + 1)).slice(-2);
	const day = ('0' + date.getDate()).slice(-2);
	return year + '/' + month + '/' + day;
}

/***
 *  @functione timeStrGetTime 
 * @dedescription 时间戳获取时间
 **/
const timeStrGetTime = (timeStr) => {
	let str = 1000 * timeStr;
	if (isNaN(str)) {
		str = timeStr
	}
	const date = new Date(str);
	const h = date.getHours();
	const m = date.getMinutes();
	const s = date.getSeconds();
	return h + ':' + m + ':' + s;
}
/***
 *  @functione numberToChinese 
 * @dedescription 数字转中文
 **/
function numberToChinese(num) {
	const chineseNums = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九'];
	const chineseUnits = ['', '十', '百', '千', '万', '亿', '兆'];

	if (num === 0) {
		return chineseNums[0];
	}

	const digits = Math.floor(num).toString().split('');
	const len = digits.length;

	let result = '';

	for (let i = 0; i < len; i++) {
		const digit = parseInt(digits[i]);
		const unit = chineseUnits[len - 1 - i];

		if (digit !== 0) {
			result += chineseNums[digit] + unit;
		} else {
			if (result[result.length - 1] !== chineseNums[0]) {
				result += chineseNums[digit]
			}
		}
	}

	return result;
}

module.exports = {
	dimension,
	HMS_daxiao,
	getDatetime,
	GetDateStr,
	getWeek,
	underDevelopment,
	timeStrGetDate,
	timeStrGetTime,
	numberToChinese
}